package com.ruoyi.ipms_patent.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.ipms_crm.dto.Employee;
import com.ruoyi.ipms_patent.dto.IpmsCaseBaseInfo;
import com.ruoyi.ipms_patent.dto.IpmsCaseBaseInfoB;
import com.ruoyi.ipms_patent.dto.IpmsCaseBaseInfoD;
import com.ruoyi.ipms_patent.dto.IpmsCaseModify;
import com.ruoyi.ipms_patent.entity.IpmsCase;
import com.ruoyi.ipms_patent.service.IpmsCaseService;
import com.ruoyi.system.api.crm.RemoteEmployeeService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: isBao
 * Description:TODO:案件controller
 */

@RestController
@RefreshScope
@RequestMapping("/patent/case")
public class CaseController extends BaseController {

    @Resource
    IpmsCaseService ipmsCaseService;

    @Resource
    RemoteEmployeeService remoteEmployeeService;

    /* 基于用户角色返回对应的案件列表 */
    @PostMapping("/list")
    public TableDataInfo getCase(@RequestBody IpmsCaseBaseInfo ipmsCaseBaseInfo){
        startPage();
        List<IpmsCaseBaseInfo> caseList = ipmsCaseService.findCaseByuserId(ipmsCaseBaseInfo);
        return getDataTable(caseList);
    }


    /* 案件新增--根据合同编号 */
    @GetMapping("/add/{contractNos}")
    public AjaxResult addCase(@PathVariable List<String> contractNos){

        return toAjax(ipmsCaseService.insertCase(contractNos));
    }

    /* 案件修改 */
    @PostMapping("/update")
    public AjaxResult updateCase(@RequestBody IpmsCaseModify ipmsCaseModify){

        return toAjax(ipmsCaseService.updateCase(ipmsCaseModify));
    }

    /* 案件删除 */
    @GetMapping("/delete/{caseNos}")
    public AjaxResult deleteCase(@PathVariable("caseNos") List<String> caseNos){

        System.out.println("caseNos"+caseNos);
        return toAjax(ipmsCaseService.delCaseByCaseNo(caseNos));
    }

    /* 案件详情基本信息 */
    @GetMapping("/detail/{caseNo}")
    public AjaxResult detailCase(@PathVariable("caseNo") String caseNo){

        return AjaxResult.success(ipmsCaseService.selectCaseByCaseNo(caseNo));
    }
    /* 案件详情申请文件 */
    @GetMapping("/detailB/{caseNo}")
    public TableDataInfo detailCaseB(@PathVariable("caseNo") String caseNo){

        List<IpmsCaseBaseInfoB> caseList = ipmsCaseService.selectCaseBByCaseNo(caseNo);
        return getDataTable(caseList);
    }

    /* 案件详情官文信息 */
    @GetMapping("/offical/{caseNo}")
    public TableDataInfo offical(@PathVariable("caseNo") String caseNo){

        List<IpmsCaseBaseInfoD> caseList = ipmsCaseService.selectOfficalByCaseNo(caseNo);
        return getDataTable(caseList);
    }

    /* 获取撰稿人 */
    @GetMapping("/getWriter")
    public AjaxResult getEmployee(){

        return AjaxResult.success(remoteEmployeeService.getEmployee());
    }


    /* 模拟官方审核 */
    @GetMapping("/official")
    public AjaxResult officialResult(){

        return toAjax(ipmsCaseService.officialResult());
    }
}
